'use strict';

// signup controller
app.controller('SignupFormController', ['$window','$scope', '$http', '$state', function($window,$scope, $http, $state) {
    $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
    $scope.account = {
        userName:"",
        loginName:"",
        password:""
    };
    $scope.authError = null;
    $scope.signup = function() {
        $scope.authError = null;
      // Try to create
      $http.post('/user/registeraccount', $.param($scope.account)).then(function(response) {
          if (!response.data) {
            $scope.authError = response;
          }else{
              $window.localStorage["userInfo"]=JSON.stringify(response.data);
              $state.go('access.chooserole');
          }
      }, function(x) {
        $scope.authError = 'Server Error';
      });
    };
  }])
 ;